package com.yolo.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author ChenBo
 * @Date 2020/10/10
 * @Version 1.0
 */
@Configuration
public class RabbitMQConfig {
    //定义交换机名
    public static final String GOODS_AD_EXCHANGE="goods_ad_exchange";

    //定义队列名
    public static final String GOODS_AD_QUEUE="goods_ad_queue";

    //声明交换机
    @Bean("GOODS_AD_EXCHANGE")
    public Exchange GOODS_AD_EXCHANGE(){
        return ExchangeBuilder.fanoutExchange(GOODS_AD_EXCHANGE).durable(true).build();
    }

    //声明队列
    @Bean("GOODS_AD_QUEUE")
    public Queue GOODS_AD_QUEUE(){
        return new Queue(GOODS_AD_QUEUE);
    }

    //队列绑定交换机
    @Bean
    public Binding GOODS_AD_BINDING(@Qualifier("GOODS_AD_QUEUE") Queue queue,
                                    @Qualifier("GOODS_AD_EXCHANGE") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("").noargs();
    }
}
